﻿/*
**营业数据汇总页面类
*/
Chenxin.UI.CBDashBord = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/CollectBusinessDashBord.ashx',
	rcId:'my_chart',
	op:'getpiedb',
	param:{charttype:'newhouse'},
	reloadDb:function(title){
		if(title){
			$('#chart_title').html(title);		
		}
		if(this.param.ParentType!=undefined){
			delete this.param.ParentType;
		}
		if(this.param.ParentId!=undefined){
			delete this.param.ParentId;
		}
		$('#a_top').nextAll().remove();
		this.reloadDashBord();
	},
	reloadDashBord:function(){	
		var pid='#chart';
		$(pid).empty();
		url=this.actionUrl+'?op='+this.op;
		for(var p in this.param){
			url+=('&'+p+'='+this.param[p]);
		}
		var _w=$(pid).width();
		
		if(this.op=='getpiedb'){//pie
			$(pid).append('<div id="'+this.rcId+'_b'+'"></div>');//买卖
			$(pid).append('<div id="'+this.rcId+'_r'+'"></div>');//租赁
		
			swfobject.embedSWF("flashchart/open-flash-chart.swf", this.rcId+'_b', _w/2, "300", "9.0.0", "expressInstall.swf",{"data-file":encodeURIComponent(url+'&column=b')},{wmode:'transparent'});
			swfobject.embedSWF("flashchart/open-flash-chart.swf", this.rcId+'_r', _w/2, "300", "9.0.0", "expressInstall.swf",{"data-file":encodeURIComponent(url+'&column=r')},{wmode:'transparent'});
			if(this.param.charttype!='viewhouse'){
				if(this.param.ParentType){
					var _t=parseInt(this.param.ParentType);
					if(_t<20){
						$(pid).append('<div id="'+this.rcId+'_a'+'"></div>');//组均
						swfobject.embedSWF("flashchart/open-flash-chart.swf", this.rcId+'_a', _w/2, "300", "9.0.0", "expressInstall.swf",{"data-file":encodeURIComponent(url+'&column=a')},{wmode:'transparent'});
					}
				}else{
					$(pid).append('<div id="'+this.rcId+'_a'+'"></div>');//组均
					swfobject.embedSWF("flashchart/open-flash-chart.swf", this.rcId+'_a', _w/2, "300", "9.0.0", "expressInstall.swf",{"data-file":encodeURIComponent(url+'&column=a')},{wmode:'transparent'});				
				}
				$(pid).append('<div id="'+this.rcId+'_t'+'"></div>');//合计				
				swfobject.embedSWF("flashchart/open-flash-chart.swf", this.rcId+'_t', _w/2, "300", "9.0.0", "expressInstall.swf",{"data-file":encodeURIComponent(url+'&column=t')},{wmode:'transparent'});
				
			}
			
		
		}else{
			$(pid).append('<div id="'+this.rcId+'"></div>');
			swfobject.embedSWF("flashchart/open-flash-chart.swf", this.rcId, _w, "300", "9.0.0", "expressInstall.swf",{"data-file":encodeURIComponent(url)},{wmode:'transparent'});
		}	
	},
    createSearch: function() {
        return new Chenxin.UI.CBDashBordSearch({
            scope: this
        });
    },
	initEvent:function(){
		var _this=this;
		$('#btn_newhouse').click(function(){	
			_this.param.charttype='newhouse';	
			_this.reloadDb(this.innerHTML);
		});
		$('#btn_housetrace').click(function(){	
			_this.param.charttype='housetrace';		
			_this.reloadDb(this.innerHTML);
		});
		$('#btn_newcustomer').click(function(){	
			_this.param.charttype='newcustomer';	
			_this.reloadDb(this.innerHTML);
		});
		$('#btn_customertrace').click(function(){
			_this.param.charttype='customertrace';	
			_this.reloadDb(this.innerHTML);
		});
		$('#btn_viewhouse').click(function(){	
			_this.param.charttype='viewhouse';	
			_this.reloadDb(this.innerHTML);
		});
		$('#btn_pie').click(function(){
			_this.op='getpiedb';
			_this.reloadDb();
		});
		$('#btn_bar').click(function(){
			_this.op='getglassbardb';
			_this.reloadDb();
		});
		
		
		$('#chart_path').find('a').live('click',function(){
			var n=$(this).attr('n');
			var i=$(this).attr('i');
			if(n==_this.param.ParentType&&i==_this.param.ParentId){
				return false;
			}
			
			if(n!=undefined){			
				_this.param.ParentType=n;
			}else{
				if(_this.param.ParentType!=undefined){
					delete _this.param.ParentType;
				}		
			}
			if(i!=undefined){
				_this.param.ParentId=i;			
			}else{
				if(_this.param.ParentId!=undefined){
					delete _this.param.ParentId;
				}					
			}
			_this.reloadDashBord();
			$(this).nextAll().remove();
			return false;
		});	
	},
	initComponent:function(){
		Chenxin.UI.CBDashBord.superclass.initComponent.call(this);
		this.reloadDashBord();
	}
});

/*
**查询条件类
*/
Chenxin.UI.CBDashBordSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    actionUrl: 'service/CollectBusinessDashBord.ashx',
    id: "house_search",
	afterGetParamJson:function(model){
		if(!model.StartDate||!model.EndDate){
			alert('请输入开始日期和结束日期');
			this.autoReload=false;
		}else{
			var sd=new Date(model.StartDate);
			var ed=new Date(model.EndDate);
			if(sd>ed){
				alert('开始日期不能大于结束日期');
			}else{
				this.autoReload=true;				
			}		
		}
	},
    initEvent: function() {
        var _this = this;
        /*************事件：查询事件*************/
        $("#btSearch").click(function() {
			var param=_this.getParamJson();
			if(!_this.autoReload){
				return ;
			}else{
				Chenxin.apply(_this.scope.param,param);
				_this.scope.reloadDb();
			}
        });		
    },
	initData:function(){
		var d=new Date();
		var _d=d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate();
		this.fitData({StartDate:_d,EndDate:_d});
	},
    initComponent: function() {        
		Chenxin.UI.CBDashBordSearch.superclass.initComponent.call(this);
		this.initData();
    }
});

var objPg;
$(document).ready(function() {
    objPg = new Chenxin.UI.CBDashBord();
});
function show(id,type,title){
	
	if(type==40||type==50){	
		return;
	}else{
		objPg.param.ParentType=type;
		objPg.param.ParentId=id;
		objPg.reloadDashBord();		
	}
	$('#chart_path').append('<a href="#" title="'+title+'" n=\"'+type+'\" i=\"'+id+'\"> >> '+title+'</a>');
	$('#chart_path').append()
	
}

